package com.lovedice.util;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.lovedice.R;

public class DiceListAdapter extends ArrayAdapter<String> {
    private List<String> mList;
    private Context mContext;

    public DiceListAdapter(Context context, int textViewResourceId, List<String> list) {
        super(context, textViewResourceId, list);
        this.mList = list;
        this.mContext = context;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        try {
            if (view == null) {
                LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                view = vi.inflate(R.layout.list_item, null);
            }
            final String listItem = (String) mList.get(position);
            if (listItem != null) {
                TextView textView = (TextView) view.findViewById(R.id.list_item_text_name);
                textView.setText(listItem);
            }
        } catch (Exception e) {
        	e.printStackTrace();
        }
        return view;
    }
}
